# _*_ coding: utf-8 _*_
# .@FileName:setting_widget
# .@Data....:2025-02-07 : 15 : 14
# .@Aurhor..:LiuJingYu
"""
launch:
   import maya.cmds as cmds
   FileName.main() 
"""

from __future__ import unicode_literals, print_function

# 导入自定义的配置模块，可能包含一些全局配置信息
import config

# 从 PySide2.QtGui 模块导入所有内容，该模块包含了与图形用户界面相关的图形、字体、颜色等功能
from PySide2.QtGui import *
# 从 PySide2.QtCore 模块导入 Qt 类，该类包含了许多 Qt 框架的常量和枚举值
from PySide2.QtCore import Qt
# 从 PySide2.QtWidgets 模块导入所有内容，该模块包含了各种用户界面组件，如按钮、文本框等
from PySide2.QtWidgets import *
import maya.cmds as mc

import setting


class FontSettingWidget(QWidget):
    def __init__(self, parent=None):
        super(FontSettingWidget, self).__init__(parent)
        self.main_layout = QHBoxLayout(self)

        self.font = QLabel(self.set_setting_font_size())

        self.font_setting_bn = QPushButton("设置")

        self.main_layout.addWidget(QLabel("字体:"))

        self.main_layout.addWidget(self.font)

        self.main_layout.addWidget(self.font_setting_bn)

        self.font_setting_bn.clicked.connect(self.set_font_setting)



    def set_setting_font_size(self):
        f = setting.get("font", None)
        if f is None:
            return QFont().toString()
        return f

    def set_font_setting(self):
        a,b = QFontDialog.getFont()
        if type(a) == bool:
            ok = a
            f = b
        else:
            ok = b
            f = a
        if ok:
            setting.set("font", f.toString())
        else:
            QMessageBox.warning(self, "警告", "设置错误")


    def paintEvent(self, *args, **kwargs):
        # 创建一个 QPainter 对象，用于在窗口部件上进行绘制操作
        p = QPainter(self)
        # 设置画笔为无，即不绘制边框
        p.setPen(Qt.NoPen)
        # 创建一个画刷，颜色为 RGB(65, 65, 65)，并将其设置为绘制的填充颜色
        p.setBrush(QBrush(QColor(65, 65, 65)))
        # 绘制一个与窗口部件大小相同的矩形
        p.drawRect(self.rect())
        # 结束绘制操作
        p.end()


class RenameWidget(QWidget):
    def __init__(self, parent=None):
        super(RenameWidget, self).__init__(parent)
        self.main_layout = QVBoxLayout(self)

        self.font_setting_widget = FontSettingWidget()
        self.main_layout.addWidget(self.font_setting_widget)
        self.main_layout.addStretch(0)


def new():
    return RenameWidget()
